package com.baichang.taoshunda.controller;

import com.baichang.framework.controller.IController;
import com.baichang.framework.controller.IPageController;
import com.baichang.framework.controller.WebBaseController;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.framework.model.Page;
import com.baichang.taoshunda.ControllerConstants;
import com.baichang.taoshunda.service.BusinessMoneyRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2018/2/25 0025.
 */
@Controller
@RequestMapping(ControllerConstants.DEPOSIT)
public class DepositWController extends WebBaseController {

    @Autowired
    private BusinessMoneyRecordService businessMoneyRecordService;

    /**
     * 保证金审核
     *
     * @return
     */
    @RequestMapping("/findAuditDeposit")
    public String findAuditDeposit() {
        return "taoshunda/deposit/depositAudit";
    }

    /**
     * 保证金记录
     *
     * @return
     */
    @RequestMapping("/findRecord")
    public String findRecord() {
        return "taoshunda/deposit/depositRecord";
    }

    /**
     * 查询需要审核的保证金
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryDeposit")
    public void queryDeposit(final HttpServletRequest request, HttpServletResponse response) {
        initPage(request, response, new IPageController() {
            @Override
            public Page initPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                String businessName = getString(request, "businessName", "");
                return businessMoneyRecordService.queryAuditingDepsoit(businessName, nowPage, pageSize);
            }
        });
    }

    /**
     * 同意审核
     *
     * @param request
     * @param response
     */
    @RequestMapping("/updateStatus")
    public void updateStatus(final HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                Integer id = getInt(request, "id", 0);
                return businessMoneyRecordService.updateStatus(id);
            }
        });
    }

    /**
     * 查询保证金的记录
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryRecord")
    public void queryRecord(final HttpServletRequest request, HttpServletResponse response) {
        initPage(request, response, new IPageController() {
            @Override
            public Page initPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                String businessName = getString(request, "businessName", "");
                return businessMoneyRecordService.queryRecord(businessName, nowPage, pageSize);
            }
        });
    }
}
